﻿namespace Typps
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.Design;

    public class SlidePaneControlDesigner : BaseControlDesigner
    {
        #region Fields

        //private DesignerAutoFormatCollection _autoFormats = null;
        FormCss form1 = null;
        string slidePaneCss = string.Empty;

        #endregion Fields

        #region Methods

        public override string GetDesignTimeHtml()
        {
            SlidePane baseComponent = (SlidePane)ViewControl;
            string designTimeHtml = base.GetDesignTimeHtml();
            string css = string.Format("<style type=\"text/css\">{0}</style>", baseComponent.GetCssStyle());
                designTimeHtml = string.Format("{0}{1}", css, designTimeHtml);
            return designTimeHtml;
        }

        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);
        }

        protected override void OnRetrieveAutoGeneratedCss(object sender, EventArgs args)
        {
            if (form1 == null)
                form1 = new FormCss(CssSelection.SlidePane);

            SlidePane baseComponent = (SlidePane)ViewControl;

            slidePaneCss = baseComponent.GetCssStyle(true);

            form1.CssSelectedIndexChanged += new CssSelectedIndexChangedEventHandler(form1_CssSelectedIndexChanged);
            form1.WhiteSpaceCheckedChanged += new WhiteSpaceCheckedChangedEventHandler(form1_WhiteSpaceCheckedChanged);
            form1.SetCss(slidePaneCss);
            form1.ShowDialog();
        }

        protected override void PreFilterProperties(System.Collections.IDictionary properties)
        {
            base.PreFilterProperties(properties);
        }

        void form1_CssSelectedIndexChanged(object sender, CssSelectedIndexChangedEventArgs e)
        {
            SetCss(e.SelectedIndex, form1.IsWhiteSpaceRemovalChecked());
        }

        void form1_WhiteSpaceCheckedChanged(object sender, WhiteSpaceCheckedChangedEventArgs e)
        {
            SetCss(e.SelectedIndex, e.CheckedStatus);
        }

        void SetCss(CssSelection cs, bool removeWhiteSpace)
        {
            string css = string.Empty;
            switch (cs)
            {
                case CssSelection.SlidePane:
                    css = slidePaneCss;
                    break;
            }
            if (removeWhiteSpace && css != string.Empty)
                css = Helper.TrimWhiteSpace(css);
            form1.SetCss(css);
        }

        #endregion Methods
    }
}